﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>方向条件-表单字段条件</title>
    <link href="../../Scripts/easyUI145/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../../Scripts/bootstrap/js/jquery.min.js"></script>
    <script type="text/javascript" src="../../Scripts/bootstrap/js/bootstrap.min.js"></script>
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../Comm/Gener.js" type="text/javascript"></script>
    <script src="../Admin.js" type="text/javascript"></script>

    <link href="../../Style/skin/css/Default.css" rel="stylesheet" />
    <link href="../../Style/skin/adminfont/iconfont.css" rel="stylesheet" />
    <link href="../../Scripts/bootstrap/css/bootstrap.min.css" rel="stylesheet" />

    <link href="../../Scripts/easyUI/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../Scripts/easyUI/themes/icon.css" rel="stylesheet" type="text/css" />

    <script src="../../Scripts/easyUI/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="../../Scripts/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../Scripts/EasyUIUtility.js" type="text/javascript"></script>

    <link href="../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <base target="_self" />

    <script type="text/javascript">

        var OperForString = null;
        var OperForNumber = null;

        //初始化页面函数.....
        $(function () {

            //两者都隐藏.
            document.getElementById("TB_Val").style.display = "none";
            document.getElementById("DDL_Val").style.display = "none";


            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_Cond");
            handler.AddUrlData();
            var data = handler.DoMethodReturnString("CondByFrm_Init");

            if (data.indexOf('err@') == 0) {
                $("#Msg").html("<font color=red>加载失败:<br>" + data + "</font> .");
                return;
            }

            //转json.
            data = JSON.parse(data);
            var sys_mapattr = data["Sys_MapAttr"];

            //绑定查询.
            GenerBindDDL("DDL_Fields", sys_mapattr, "No", "Name", "all");

            var cond = data["WF_Cond"];
            if (cond != null && cond != undefined) {
                cond = cond[0];
                $("#DDL_Fields").val(cond.AttrKey);
                changeCond($("#DDL_Fields")[0]);
                $("#DDL_Operator").val(getOperText(cond.FK_Operator));
                $("#TB_Val").val(cond.OperatorValue);
                $("#DDL_Val").val(cond.OperatorValue);
            }


        });

        function getOperText(Oper) {
            if (Oper == "")
                return "all";
            switch (Oper) {
                case "=":
                    return "dengyu";
                case ">":
                    return "dayu";
                case ">=":
                    return "dayudengyu";
                case "<":
                    return "xiaoyu";
                case "<=":
                    return "xiaoyudengyu";
                case "!=":
                    return "budengyu"
                case "LIKE":
                    return "like";
                default:
                    return "all";
            }

        }
        //执行保存..
        function Save() {


            var DDL_Fields = $("#DDL_Fields").val(); //  字段.
            var DDL_Operator = $("#DDL_Operator").val(); //  操作符.

            var OperVal = "";

            var tb = document.getElementById("TB_Val");
            var tbText = document.getElementById("TB_Text");
            if (tb.style.display == "" || tbText.style.display == "inline") {
                OperVal = tb.value;
            } else {
                OperVal = $("#DDL_Val").val(); //  操作符.
            }

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_Cond");
            handler.AddPara("DDL_Fields", DDL_Fields);
            handler.AddPara("DDL_Operator", DDL_Operator);
            handler.AddPara("OperVal", OperVal);
            handler.AddPara("OperValText", encodeURI(tbText.value));
            handler.AddUrlData();
            var data = handler.DoMethodReturnString("CondByFrm_Save");

            if (data.indexOf('err@') == 0) {
                $("#Msg").html("<font color=red>" + data + "</font>");
                return;
            }

            if (data.indexOf('url@') == 0) {
                var url = data.replace('url@', '');
                SetHref(url);
                return;
            }
            Back();
        }

        //当字段选择的时候.
        function changeCond(c) {

            if (c == null || c.value.length == 0)
                return;

            var key = c.value;
            if (key == "all")
                return;

            var fk_flow = GetQueryString("FK_Flow");

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_Cond");
            handler.AddPara("FK_Flow", fk_flow);
            handler.AddPara("KeyOfEn", key);

            var data = handler.DoMethodReturnString("CondByFrm_InitField");

            if (data.indexOf('err@') == 0) {
                $("#Msg").html("<font color=red>" + data + "</font>");
                return;
            }

            if (data.indexOf('url@') == 0) {
                var url = data.replace('url@', '');
                SetHref(url);
                return;
            }

            data = JSON.parse(data);

            //获得 mapattr.
            var mapattr = data["Sys_MapAttr"][0];
            //操作符.
            var opers = data["Opers"];

            //两者都隐藏.
            document.getElementById("TB_Val").style.display = "none";
            document.getElementById("TB_Text").style.display = "none";
            document.getElementById("DDL_Val").style.display = "none";
            $("#opts").html("");


            /*是枚举类型*/
            if (mapattr.LGType == "1") {

                var enums = data["Enums"];
                GenerBindDDL("DDL_Val", enums, "IntKey", "Lab", 0);
                //显示.
                document.getElementById("DDL_Val").style.display = "";
            }

            if (mapattr.LGType == "2" || (mapattr.LGType == "0" && mapattr.MyDataType == "1" && mapattr.UIContralType == 1)) {
                document.getElementById("TB_Text").style.display = "inline";
                $("#opts").html("<input type='button' onclick=\"javascript:SelectFKData('" + mapattr.MyPK + "');\" value='请选择数据' />");
            }

            if (mapattr.LGType == "0" && mapattr.UIContralType != 1) {
                document.getElementById("TB_Val").style.display = "";
            }

            //绑定操作符.
            GenerBindDDL("DDL_Operator", opers, "No", "Name", "=");
        }
        ///选择外部数据.
        var newWindow = "";
        function SelectFKData(fk_mapAttr) {
            OpenEasyUiDialogExt('CondByFrmSelectFKData.htm?FK_MapAttr=' + fk_mapAttr, '选择一个值', '600', '400', false);
        }
        function getValue(data) {
            $('#eudlg').dialog('close');
            $("#TB_Val").val(data[0]);
            $("#TB_Text").val(data[1]);
        }

        //返回.
        function Back() {
            var url = GetHrefUrl();
            url = url.replace('CondByFrm.htm', 'List.htm');
            if (url.indexOf("MyPK=") != -1) {
                url = url.replace("&MyPK=" + GetQueryString("MyPK"), "");
            }
            SetHref(url);

        }
        //检查流程.
        function FlowCheck() {
            var flowNo = GetQueryString("FK_Flow");
            var flowId = Number(flowNo);
            flowId = String(flowId);


            $("#Btn_Check").attr('value', '正在检查请稍后');

            var flow = new Entity("BP.WF.Flow", flowNo);
            var data = flow.DoMethodReturnString("DoCheck");

            $("#Btn_Check").attr('value', '检查成功，请设置条件');
            alert("执行成功...");
            return;

            WinOpen(url);
            var url = "";
            if (typeof top.layui == "undefined") {
                url = "../AttrFlow/CheckFlow.htm?FK_Flow=" + flowNo + "&FK_MapData=ND" + flowId + "MyRpt";
                OpenEasyUiDialog(url, "FlowCheck" + flowNo, "检查流程" + flowNo, 600, 500, "icon - library", false, null, null, null, dlgClosedFunc);
            }

            else {
                url = "../AttrFlow/CheckFlow.htm?FK_Flow=" + flowNo + "&FK_MapData=ND" + flowId + "MyRpt";
                OpenLayuiDialog(url, "检查流程" + flowNo, window.innerWidth * 2 / 3);
            }
        }
        function DoCheck()
        {
            var val = window.confirm('提示:\t\n1.如果没有您期望的字段,请在流程设计器中检查一下流程. \t\n2.检查流程后，节点表单字段才能汇总上来. \t\n3.您要执行检查流程吗？');
            if (val == true)
                FlowCheck();
        }
        function dlgClosedFunc() {
            window.location.reload();
            // window.location.refresh();
        }

    </script>
</head>
<body>
    <div class="container-full">
        <div class="attrnode-bar-header">
            <span class="pull-right">

                <button id="Btn_Save" name="Btn_Save" onclick="Save();">保存</button>
                <button id="Btn_Check" name="Btn_Check" class="cc-btn-tab btn-save" onclick="FlowCheck()">检查流程</button>
                <button id="Btn_Back" name="Btn_Back" onclick="Back();">返回</button>

            </span>
            <strong>按照表单的字段作为条件</strong>
        </div>
        <form id="cc">

            <table id="table" class="table">

                <tr>
                    <td style="width:20%;">选择表单字段: </td>
                    <td>
                        <select id="DDL_Fields" name="DDL_Fields" onchange="changeCond(this)"></select>
                        <a href="javascript:DoCheck()">  <img src='../../Img/Btn/Help.gif' /> 为什么没有我要的字段？</a>
                    </td>
                </tr>

                <tr>
                    <td style="width:20%;">操作符: </td>
                    <td><select id="DDL_Operator" name="DDL_Operator" style="width:100px;"></select> </td>
                </tr>

                <tr>
                    <td style="width:20%;">值: </td>
                    <td>
                        <input type="text" value="" style="width:100px;" id="TB_Val" name="TB_Val" />
                        <input type="text" value="" style="width:100px;" id="TB_Text" name="TB_Text" />
                        <span id="opts"> </span>
                        <br />
                        <select id="DDL_Val" name="DDL_Val" style="width:100px;">  </select>


                    </td>
                </tr>

            </table>


        </form>

        <center><div id="Msg" /></center>

    </div>

</body>
</html>

